package com.ycy.servlet;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * 1 这个Servlet可以通过 web.xml 来加载 或者 可以通过 spi (Service Provider Interface) 是一种服务发现机制
 * 2 这个servlet 只有 url 访问后才实例
 */
public class YcyServiceServlet extends HttpServlet {

  Logger logger = LoggerFactory.getLogger(this.getClass());

  public YcyServiceServlet() {
    logger.warn("实例化完成");
  }

  @Override
  protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    String x = "hellword " + this;
    logger.warn(x);
    resp.setContentType("text");
    PrintWriter writer = resp.getWriter();
    writer.println(x);
    writer.close();
  }

}
